/*
    Document   : commom
    Created on : 2011-04-14, 8:34:41
    Author     : YuanLei
    * commom.js 公用JS
*/
$(function(){
    slideShow();
   openLoginPop();
   $("#changecode").click(function(){
        $("#captchaImage").attr("src",'http://my.33e9.net:83/cp-website/security/jcaptcha.do?q='+new Date().getTime())
   });

   funlinks()
});

/**
 * 幻灯效果
 */
function slideShow() {
    
    var btn=$(".focus-btn a");
    var changeimg=$("#focus li");
    btn.click(function(){
        var i=btn.index($(this));
        $(this).addClass("current").siblings().removeClass("current");
        changeimg.eq(i).fadeIn().siblings().fadeOut();
    }).hover(function(){
        $(this).stop(true).animate({
            opacity:1
        },400);
    }, function(){
        if(!$(this).is(".current")){
            $(this).animate({
                opacity:0.5
            },400)
        }else{
            $(this).show().removeAttr("style");
        }
    });
    var version='<div class="version_info"><span>版本：V1.0.1.8Beta</span><span>系统：WIN 2K/XP/VISTA/7</span><span>大小：8.7M</span><span>更新：2011年07月08日</span>'
    changeimg.eq(0).append(version);
    if($("#focus").length>0){
        slideShow.time=setInterval(function(){slide()},5000);
    }
}
function slide(){
    
    var i=$(".focus-btn a").index($(".focus-btn .current")[0])+1;
    if(i>$(".focus-btn a").length-1){
        i=0;
    }
    $(".focus-btn a").eq(i).addClass("current").siblings().removeClass("current");
    $("#focus li").eq(i).fadeIn().siblings().fadeOut();
}


/**
 * 核心功能链接
 */
function funlinks() {
    var arrurl=["book.html#focus","call.html#focus","status.html#focus","phone.html#focus","gain.html#focus","terminal.html#focus","meeting.html#focus","multi.html#focus"];
    
    $(".fun li").each(function(i){
        $(this).css("cursor","pointer").click(function(){
            window.location="features/"+arrurl[i];
        });
    })
}

/**
 * 弹出登录
 */
function openLoginPop() {
    $("#loginbtn").attr("href","javascript:void(0);").click(function(){
        $("#popLogin").PopupDiv({
            modal : true,
            minWidth :400,
            PopupDivId : "Popuplogin"
        });
    });
    $("body").append(loginHtml());
}
/**
 * 关闭弹出层
 */
function closeLoginPop() {
    $("#popLogin").PopupDiv("remove");
}
/**
 * 验证登录
 */
function checkloginForm(parameters) {
    var flag=true;
    var mobileNo=$.trim($("#j_username").val());
    var usernameMsg=$("#usernameMsg");
    if(!/^\d{10}\d$/.test(mobileNo)&&!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(mobileNo)){
        usernameMsg.html("请填写正确的帐号");
        flag=false;
    }else{
        usernameMsg.html('');
    }
    var password=$.trim($("#j_password").val());
    var passwordMsg=$("#passwordMsg");
    if(password==""){
        passwordMsg.html("请填写密码");
        flag=false;
    }else{
        passwordMsg.html("");
    }
    var code=$.trim($("#_captcha_parameter").val());
    var codeMsg=$("#codeMsg");
    if(code==""){
        codeMsg.html("请填写验证码");
        flag=false;
    }else{
        codeMsg.html("");
    }
    if(flag){
        closeLoginPop();
    }
    return flag;
}

/**
 * 登录窗口html
 */
function loginHtml(parameters) {
    var _$out=[];
    _$out.push('<div class="hide" id="popLogin" poptitle="登录我的话伴">');
    _$out.push('        <div class="myContent poplogin clearfix">');
    _$out.push('            <form onsubmit="return checkloginForm();" action="http://my.33e9.net:83/cp-website/j_acegi_security_check" target="_blank">');
    _$out.push('                <table cellspacing="0" cellpadding="0" border="0">');
    _$out.push('                    <tbody>');
    _$out.push('                        <tr>');
    _$out.push('                            <th>帐　号：</th>');
    _$out.push('                            <td><input type="text" onblur="if(this.value==\'\'){this.value=\'手机号码/邮箱\';}" onfocus="if(this.value==\'手机号码/邮箱\'){this.value=\'\';}" value="手机号码/邮箱" id="j_username" name="j_username"/>');
    _$out.push('                            </td>');
    _$out.push('                            <td class="red" id="usernameMsg"></td>');
    _$out.push('                        </tr>');
    _$out.push('                        <tr>');
    _$out.push('                            <th>密　码：</th>');
    _$out.push('                            <td><input type="password" id="j_password" name="j_password"/></td>');
    _$out.push('                            <td class="red" id="passwordMsg"></td>');
    _$out.push('                        </tr>');
    _$out.push('                        <tr>');
    _$out.push('                            <th>验证码：</th>');
    _$out.push('                            <td>');
    _$out.push('                                <input type="text" id="_captcha_parameter" name="_captcha_parameter"/>');
    _$out.push('                            </td>');
    _$out.push('                            <td class="red" id="codeMsg"></td>');
    _$out.push('                        </tr>');
    _$out.push('                        <tr>');
    _$out.push('                            <th></th>');
    _$out.push('                            <td colspan="2">');
    _$out.push('                                <img width="60" height="20" src="http://my.33e9.net:83/cp-website/security/jcaptcha.do?q=+Math.random()" id="captchaImage" alt=""/>');
    _$out.push('                                <a href="javascript:void(0);" id="changecode" class="blue loginreg">看不清换一张!</a>');
    _$out.push('                            </td>');
    _$out.push('                        </tr>');
    _$out.push('                        <tr>');
    _$out.push('                            <th></th>');
    _$out.push('                            <td colspan="2">');
    _$out.push('                                <span class="reg">还没有我的话伴帐号?　<a href="http://my.33e9.net:83/cp-website/cpuser/goRegister.do" target="_blank" class="blue" onclick="closeLoginPop();">立即注册</a> </span>');
    _$out.push('                            </td>');
    _$out.push('                        </tr>');
    _$out.push('                    </tbody></table>            ');
    _$out.push('            <p class="pop-bottom"><input type="submit" id="btn_login" value="登　录" class="submit_button" tabindex="5" name="button"/>　　　<a href="http://my.33e9.net:83/cp-website/page/forgetpwd/forgetPWDSelect.jsp" target="_blank" class="blue" onclick="closeLoginPop();">忘记密码?</a></p>');
    _$out.push('</form>');
   _$out.push('         </div>');
   _$out.push('     </div><!-- End .hide -->');
   return _$out.join("");
}

